<script type="text/javascript" src="jquery-1.8.3.min.js"></script>
<link rel="stylesheet"  type="text/css"  href="bootstrap.css" >
<html>
<head>
    <meta charset="utf-8">
    <title>Title</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }
        html {
            height: 100%;
        }
        body {
            background:url(https://img.51miz.com/Element/00/59/33/44/6766b1bb_E593344_6baa5e03.jpg)no-repeat center center;
            height: 100%;
            width: 100%;
            background-size:cover;
            position:absolute;
            left:0;
            top:0
        }
    </style>
</head>
<body>
<div class="container">
        <center>
            <h3>欢迎使用成绩管理系统</h3>
            <h5>绑定教师学生关系</h5>
        </center>
        <div>
            <li>教师</li><span id="jiaoshiSpan"></span><br>
            <li>学生</li><span id="xueshengSpan"></span><br>
        </div>

        <div class="form-group">
            <input type="button" onclick="f2()" value="返回" class="btn btn-primary">
            <input type="button" onclick="f1()" value="绑定" class="btn btn-primary">
        </div>

</div>
</body>
</html>
<script>
    function f2(){
        window.location.href="main.html";
    }
    function f1(){
        var jiaoshiid = $("#jiaoshiid").val();
        var xueshengid = $("#xueshengid").val();
        if(jiaoshiid=="" || xueshengid==""){
            alert("请输入完整信息");
            return;
        }
        $.ajax({
            "url":"/addXueshengjiaoshi",
            "data": {
                'jiaoshiid':jiaoshiid,
                'xueshengid':xueshengid
            },
            "type":"post",
            "dataType":"text",
            "success":function(json) {
                alert(json);
                if("绑定成功"==json){
                    window.location.href="main.html";
                }else{
                    $("#xingming").val("");
                    $("#nianling").val("");
                    $("#zhicheng").val("");
                }
            }
        });
    }
    $(function () {
        showJiaoshi();
        showXuesheng();
    })
    function showJiaoshi(){
        $.ajax({
            url: "findAllJiaoshi",
            type: "post",
            async: false,
            cache: false,
            dataType: "json",
            "success": function (json) {
                // 创建select元素的HTML字符串
                var selectHTML = "<select id='jiaoshiid' class=\"selectpicker col-md-8\">";
                for(var i=0;i<json.length;i++){
                    var obj = json[i];
                    selectHTML += "<option value='"+obj.id+"'>"+obj.xingming+"</option>";
                }
                selectHTML += "</select>";
                $("#jiaoshiSpan").html(selectHTML);
            }
        });
    }
    function showXuesheng(){
        $.ajax({
            url: "findAllXuesheng",
            type: "post",
            async: false,
            cache: false,
            dataType: "json",
            "success": function (json) {
                // 创建select元素的HTML字符串
                var selectHTML = "<select id='xueshengid' class=\"selectpicker col-md-8\">";
                for(var i=0;i<json.length;i++){
                    var obj = json[i];
                    selectHTML += "<option value='"+obj.id+"'>"+obj.xingming+"</option>";
                }
                selectHTML += "</select>";
                $("#xueshengSpan").html(selectHTML);
            }
        });
    }
</script>